package view.GUI.adminView.coreData.product;

import javafx.stage.Stage;
import model.data.tableModel.TableControl;
import model.data.tableModel.sale.Product;
import view.GUI.mainView.MainView;
import enums.GUIText;
import enums.Status;


public final class NewProduct extends AbstractProductView{

	public NewProduct(MainView instance) {
		super(false, instance, GUIText.NEWPRODUCT);
		try {
			start(new Stage());
		} catch (Exception e) {
			log.error(e.getMessage());
			e.printStackTrace();
		}
	}

	@Override
	protected boolean save() {
		Product newProduct = Product.createNewProduct(Double.valueOf(txtCost.getText()), txtName.getText(), 0, 0, Double.valueOf(txtSalePrice.getText()), cmbDeposit.getSelectionModel().getSelectedItem(), Status.ACTIVE, Integer.valueOf(txtStock.getText()), Integer.valueOf(txtMultiplicator.getText()), cmbCategory.getSelectionModel().getSelectedItem(), null, Integer.valueOf(txtMaxStock.getText()), Integer.valueOf(txtTrayCount.getText()), TableControl.getCentralCounter());
		owner.addProduct(newProduct);
		return newProduct.writeToDB();
	}	
}
